home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / cp2dekit / samples / smptwin.cpp < prev    next >
C/C++ Source or Header  |  1996-12-29  |  5KB  |  215 lines

  1. //***************************************************************************
  2. //
  3. // this file is (c) '94-'96 Niklas Beisert
  4. //
  5. // this file is part of the cubic player development kit.
  6. // you may only use/modify/spread this file under the terms stated
  7. // in the cubic player development kit accompanying documentation.
  8. //
  9. //***************************************************************************
  10.  
  11. //[general]
  12. //  link=smptwin
  13. //[screen]
  14. //  deftmodes=_cpiTModeWinTest
  15.  
  16. // textmode window example
  17. // master volume example
  18.  
  19. #include <string.h>
  20. #include "poutput.h"
  21. #include "cpiface.h"
  22.  
  23. static int plMVolFirstLine;
  24. static int plMVolHeight;
  25. static int plMVolWidth;
  26. static int plMVolType;
  27.  
  28. static void logvolbar(int &l, int &r)
  29. {
  30.   if (l>32)
  31.     l=32+((l-32)>>1);
  32.   if (l>48)
  33.     l=48+((l-48)>>1);
  34.   if (l>56)
  35.     l=56+((l-56)>>1);
  36.   if (l>64)
  37.     l=64;
  38.   if (r>32)
  39.     r=32+((r-32)>>1);
  40.   if (r>48)
  41.     r=48+((r-48)>>1);
  42.   if (r>56)
  43.     r=56+((r-56)>>1);
  44.   if (r>64)
  45.     r=64;
  46. }
  47.  
  48. static void drawpeakpower(int y, int x)
  49. {
  50.   short strbuf[40];
  51.   writestring(strbuf, 0, plPause?0x08:0x07, " [∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ -- ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙] ", 40);
  52.   int l,r;
  53.   plGetRealMasterVolume(l, r);
  54.   logvolbar(l, r);
  55.   l=(l+2)>>2;
  56.   r=(r+2)>>2;
  57.   if (plPause)
  58.   {
  59.     writestring(strbuf, 18-l, 0x08, "■■■■■■■■■■■■■■■■", l);
  60.     writestring(strbuf, 22, 0x08, "■■■■■■■■■■■■■■■■", r);
  61.   }
  62.   else
  63.   {
  64.     writestringattr(strbuf, 18-l, "■\x0F■\x0F■\x0B■\x0B■\x0B■\x0B■\x09■\x09■\x09■\x09■\x01■\x01■\x01■\x01■\x01■\x01"+32-l-l, l);
  65.     writestringattr(strbuf, 22, "■\x01■\x01■\x01■\x01■\x01■\x01■\x09■\x09■\x09■\x09■\x0B■\x0B■\x0B■\x0B■\x0F■\x0F", r);
  66.   }
  67.   displaystrattr(y, x, strbuf, 40);
  68.   if (plMVolHeight==2)
  69.     displaystrattr(y+1, x, strbuf, 40);
  70. }
  71.  
  72. static void drawbigpeakpower(int y, int x)
  73. {
  74.   short strbuf[80];
  75.   writestring(strbuf, 0, plPause?0x08:0x07, "   [∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙ -=≡≡=- ∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙∙]   ", 80);
  76.   int l,r;
  77.   plGetRealMasterVolume(l, r);
  78.   logvolbar(l, r);
  79.   l=(l+1)>>1;
  80.   r=(r+1)>>1;
  81.   if (plPause)
  82.   {
  83.     writestring(strbuf, 36-l, 0x08, "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■", l);
  84.     writestring(strbuf, 44, 0x08, "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■", r);
  85.   }
  86.   else
  87.   {
  88.     writestringattr(strbuf, 36-l, "■\x0F■\x0F■\x0F■\x0F■\x0B■\x0B■\x0B■\x0B■\x0B■\x0B■\x0B■\x0B■\x09■\x09■\x09■\x09■\x09■\x09■\x09■\x09■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01"+64-l-l, l);
  89.     writestringattr(strbuf, 44, "■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x01■\x09■\x09■\x09■\x09■\x09■\x09■\x09■\x09■\x0B■\x0B■\x0B■\x0B■\x0B■\x0B■\x0B■\x0B■\x0F■\x0F■\x0F■\x0F", r);
  90.   }
  91.   displaystrattr(y, x, strbuf, 80);
  92.   if (plMVolHeight==2)
  93.     displaystrattr(y+1, x, strbuf, 80);
  94. }
  95.  
  96. static void MVolDraw(int focus)
  97. {
  98.   if (plMVolType==3)
  99.   {
  100.     displayvoid(plMVolFirstLine, 80, 8);
  101.     displayvoid(plMVolFirstLine, 128, 4);
  102.     if (plMVolHeight==2)
  103.     {
  104.       displayvoid(plMVolFirstLine+1, 80, 8);
  105.       displayvoid(plMVolFirstLine+1, 128, 4);
  106.     }
  107.     drawpeakpower(plMVolFirstLine, 88);
  108.   }
  109.   else
  110.   {
  111.     int l=(plMVolWidth==132)?26:20;
  112.     displaystr(plMVolFirstLine, 0, plPause?0x08:0x07, "  peak power level:", l);
  113.     displayvoid(plMVolFirstLine, plMVolWidth-l, l);
  114.     if (plMVolHeight==2)
  115.     {
  116.       displayvoid(plMVolFirstLine+1, 0, l);
  117.       displayvoid(plMVolFirstLine+1, plMVolWidth-l, l);
  118.     }
  119.     if (plMVolWidth==132)
  120.       drawbigpeakpower(plMVolFirstLine, l);
  121.     else
  122.       drawpeakpower(plMVolFirstLine, l);
  123.   }
  124. }
  125.  
  126. static void MVolSetWin(int xpos, int wid, int ypos, int hgt)
  127. {
  128.   plMVolFirstLine=ypos;
  129.   plMVolHeight=hgt;
  130.   plMVolWidth=wid;
  131. }
  132.  
  133. static int MVolGetWin(cpitextmodequerystruct &q)
  134. {
  135.   if (plMVolType==2)
  136.     plMVolType=3;
  137.   if ((plMVolType==3)&&(plScrWidth!=132))
  138.     plMVolType=0;
  139.   int pplheight=(plScrHeight>30)?2:1;
  140.  
  141.   switch (plMVolType)
  142.   {
  143.   case 0:
  144.     return 0;
  145.   case 1:
  146.     q.xmode=3;
  147.     break;
  148.   case 2:
  149.     q.xmode=1;
  150.     break;
  151.   case 3:
  152.     q.xmode=2;
  153.     break;
  154.   }
  155.   q.size=0;
  156.   q.top=1;
  157.   q.killprio=128;
  158.   q.viewprio=176;
  159.   q.hgtmax=pplheight;
  160.   q.hgtmin=pplheight;
  161.   return 1;
  162. }
  163.  
  164. static int MVolIProcessKey(unsigned short key)
  165. {
  166.   switch (key)
  167.   {
  168.   case '%':
  169.     cpiTextSetMode("wtest");
  170.     break;
  171.   case 'x': case 'X':
  172.     plMVolType=3;
  173.     return 0;
  174.   case 0x2d00: //alt-x
  175.     plMVolType=1;
  176.     return 0;
  177.   default:
  178.     return 0;
  179.   }
  180.   return 1;
  181. }
  182.  
  183. static int MVolAProcessKey(unsigned short key)
  184. {
  185.   switch (key)
  186.   {
  187.   case '%':
  188.     plMVolType=(plMVolType+1)%4;
  189.     cpiTextRecalc();
  190.     break;
  191.   default:
  192.     return 0;
  193.   }
  194.   return 1;
  195. }
  196.  
  197. static int MVolCan()
  198. {
  199.   return !!plGetRealMasterVolume;
  200. }
  201.  
  202. static int MVolEvent(int ev)
  203. {
  204.   switch (ev)
  205.   {
  206.   case cpievInit: return MVolCan();
  207.   }
  208.   return 1;
  209. }
  210.  
  211. extern "C"
  212. {
  213.   cpitextmoderegstruct cpiTModeWinTest = {"wtest", MVolGetWin, MVolSetWin, MVolDraw, MVolIProcessKey, MVolAProcessKey, MVolEvent};
  214. };
  215.